package com.tulele.vtool.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.tulele.vtool.config.JinPaiDataConfig;
import com.tulele.vtool.mapper.ImportUsersJinpaiMapper;
import com.tulele.vtool.model.*;
import com.tulele.vtool.model.combinedEntity.UserBrandCombinedInfo;
import com.tulele.vtool.model.combinedEntity.WxPushUserInfo;
import com.tulele.vtool.model.reqEntity.ChangeOpenidReqBean;
import com.tulele.vtool.model.reqEntity.PurchaseVipServiceReqBean;
import com.tulele.vtool.model.reqEntity.WxUserLoginReqBean;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.*;
import com.tulele.vtool.task.async.ArticleAsyncTask;
import com.tulele.vtool.task.async.SendkefuMsgAsyncTask;
import com.tulele.vtool.task.async.UserAsyncTask;
import com.tulele.vtool.utils.*;
//import com.tulele.vtool.wechat.WechatPayConfig;
import com.tulele.vtool.wechat.WechatPayDL;
import com.tulele.vtool.wechat.service.WeixinServiceDL;
import com.tulele.vtool.wechat.service.WeixinServiceMap;
import com.tulele.vtool.wechat.service.WeixinServiceNew;
import com.tulele.vtool.wechat.token.server.AccessTokenMemServer;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.bean.menu.WxMenuRule;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
import org.apache.catalina.User;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.sql.ResultSet;
import java.util.*;

import static com.tulele.vtool.utils.ToolUtil.md5Encode;

@RestController
@Slf4j
@RequestMapping("/wechat")
public class WechatHandler {
    // 用户迁移接口URL,详情见 https://kf.qq.com/faq/1901177NrqMr190117nqYJze.html
    private String USER_CHANGE_OPENID_URL = "https://api.weixin.qq.com/cgi-bin/changeopenid?access_token=%s";

    @Autowired
    private ObjectFactory<WeixinServiceDL> objectFactory;

//    @Autowired
//    private WeixinService weixinService;

//    @Autowired
//    private WxPayService wxPayService;

    @Autowired
    private IUserInfoService userInfoService;

    @Autowired
    private IVipInfoService vipInfoService;

    @Autowired
    private IOrderInfoService orderInfoService;

//    @Autowired
//    private WechatAccountConfig wechatAccountConfig;

    @Autowired
    private UserAsyncTask userAsyncTask;

    @Autowired
    private SendkefuMsgAsyncTask sendkefuMsgAsyncTask;

    @Autowired
    private RedisCacheUtil redisCacheUtil;

//    @Autowired
//    private PlatformSysInfoConfig platformSysInfoConfig;

    @Autowired
    private IUserPromotionSettleInfoService userPromotionSettleInfoService;

    @Autowired
    private ImportUsersService importUsersService;

    @Autowired
    private ILookArticleInfoService iLookArticleInfoService;

//    @Value("${spring.profiles.active}")
//    private String springProfilesActive;

    //开放平台用户分组标识
//    @Value("${openGroupCode}")
//    private String openGroupCode;

    @Autowired
    private SysGzhService sysGzhService;

    @Autowired
    private IUserBrandInfoService userBrandInfoService;

    @Autowired
    private IUserRelateArticleTypeInfoService iUserRelateArticleTypeInfoService;

    @Autowired
    private JinPaiDataConfig jinPaiDataConfig;

    @Autowired
    private ImportUsersJinpaiMapper importUsersJinpaiMapper;

    @Autowired
    private WantedUsersService wantedUsersService;

    /**
     * 微信支付佣金余额前缀
     */
    private static final String WECHATPAYACCOUNTBALANCELAST = "WECHATPAYACCOUNTBALANCELAST:";

    /**
     * 优惠券前缀
     */
    private static final String COUPON_PRE = "ADD_COUPON_TIMELINESS:";

    /**
     * 客服赠送优惠券时效 单位：分钟
     */
    private static  final double COUPON_TIMELINESS = 30;

    /**
     * 服务对象
     */
    @Autowired
    private BBusinessInfoService bBusinessInfoService;

    @Autowired
    private UserGroupGzhService userGroupGzhService;

    /**
     * 接收到来自微信服务器的认证消息（包括微信公众号服务端配置时，验证token）
     * @param signature
     * @param timestamp
     * @param nonce
     * @param echostr
     * @return
     */
    @RequestMapping(value = "verifyToken", produces = "text/plain;charset=utf-8")
    public String verifyToken(@RequestParam(name = "signature", required = false) String signature,
                          @RequestParam(name = "timestamp", required = false) String timestamp,
                          @RequestParam(name = "nonce", required = false) String nonce,
                          @RequestParam(name = "echostr", required = false) String echostr,
                              @RequestParam(name = "gzhCode", required = false) String gzhCode
    ) {
        log.info("接收到来自微信服务器的认证消息：[{}, {}, {}, {}]", signature, timestamp, nonce, echostr);

//        WeixinServiceDL weixinService= objectFactory.getObject();
//        weixinService.reSetConfigStorage(gzhCode);
        //log.error("********[verifyToken] "+WeixinServiceMap.getWeixinServiceMap().size()+"  *******\n");
        WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(gzhCode);
        if(weixinService==null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(gzhCode);
            WeixinServiceMap.putWeixinService(gzhCode,weixinService);
            //log.error("********[verifyToken] weixinService==null  *******\n");
        }

        if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
            throw new IllegalArgumentException("请求参数非法，请核实!");
        }

        if (weixinService.checkSignature(timestamp, nonce, signature)) {
            return echostr;
        }

        return "invalidRequest";
    }

    @RequestMapping(value = "receiveWxReq", produces = "application/xml; charset=UTF-8")
    public String receiveWxReq(@RequestBody(required=false) String requestBody, @RequestParam("signature") String signature,
                       @RequestParam(name = "encrypt_type", required = false) String encType,
                       @RequestParam(name = "msg_signature", required = false) String msgSignature,
                       @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce,
                               @RequestParam(name = "echostr", required = false) String echostr,  //20200206添加，用于 微信公众号服务端配置时，验证token
                               @RequestParam(name = "gzhCode", required = false) String springProfilesActive
    ) throws Exception {

        log.error("接收微信请求：[signature=[{}], encType=[{}], msgSignature=[{}],"
                        + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] , echostr=[{}]",
                signature, encType, msgSignature, timestamp, nonce, requestBody, echostr);

        //log.error("执行receiveWxReq开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        WeixinServiceDL weixinService = WeixinServiceMap.getWeixinService(springProfilesActive);
        if (weixinService == null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            WeixinServiceMap.putWeixinService(springProfilesActive, weixinService);
        }

        PlatformSysInfo platformSysInfo = sysGzhService.getPlatformSysInfo(springProfilesActive);
        SysGzh sysGzh = platformSysInfo.getSysGzh();

        if (!weixinService.checkSignature(timestamp, nonce, signature)) {
            throw new IllegalArgumentException("非法请求，可能属于伪造的请求！");
        }

        if (requestBody == null && weixinService.checkSignature(timestamp, nonce, signature)) { //20200206添加，用于 微信公众号服务端配置时，验证token
            return echostr;
        }

        String out = null;
        if (encType == null) {

            // 明文传输的消息
            WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);

            log.info("[消息明文传输内容为] = " + inMessage);

            if (inMessage != null && inMessage.getEvent() != null && inMessage.getEvent().toUpperCase().equals("TEMPLATESENDJOBFINISH")) {//如果是模板消息的回调，直接返回 success

                log.info("捕捉到TEMPLATESENDJOBFINISH");
                return "success";
            }

            WxMpXmlOutMessage outMessage = weixinService.route(inMessage);

            //添加缓存信息
            String userOpenId = inMessage.getFromUser();
            if (StringUtils.isNotBlank(userOpenId)) {

                Integer userId = userInfoService.getUserStatusByOpenId(userOpenId);
                if (userId != null && userId.intValue() > 0) {

                    int userSubStatus = 0;

                    WxMpUser userWxInfo = new WxMpUser();
                    try {
                        userWxInfo = weixinService.getUserService().userInfo(inMessage.getFromUser(), null);
                        boolean userSubscribeStatus = userWxInfo.getSubscribe();
                        if (userSubscribeStatus) {
                            userSubStatus = 1;
                        }

                    } catch (WxErrorException e) {
                        e.printStackTrace();
                    }

                    //region 20210126 更新用户的状态
                    try {
                        UserInfo userInfo = new UserInfo();
                        userInfo.setUserId(userId);
                        userInfo.setWxUnionId(userWxInfo.getUnionId());
                        //userInfo.setUserName(userWxInfo.getNickname());//getUserService()不再返回头像和昵称
                        userInfo.setConcernStatus(userSubStatus);
                        if (userSubStatus == 1 && userWxInfo.getSubscribeTime() != null && userWxInfo.getSubscribeTime() > 0) {  //20210126
                            userInfo.setSubscribeTime(DateUtil.timeStampToDate(userWxInfo.getSubscribeTime().toString()));
                        }
                        userInfo.setLastActiveTime(DateUtil.getCurDate());

                        if (sysGzh.getOpenGroupCode() != null && sysGzh.getOpenGroupCode().trim().length() > 0) {
                            userInfo.setOpenGroupCode(sysGzh.getOpenGroupCode());//开放平台分组标识
                        }

                        //20210423 处理vip状态 start
                        UserVipValidInfo userVipValidInfoInDB = vipInfoService.getVipValidInfo(userId);
                        if (userVipValidInfoInDB != null
                                && userVipValidInfoInDB.getBeginTime()!= null
                                && userVipValidInfoInDB.getEndTime() != null
                                && userVipValidInfoInDB.getBeginTime().getTime() < DateUtil.getCurDate().getTime()
                                && DateUtil.getCurDate().getTime() < userVipValidInfoInDB.getEndTime().getTime()) {//开始时间 和 结束时间 之内
                            userInfo.setVipStatus(1);
                        } else {
                            userInfo.setVipStatus(0);//把vip关掉
                        }
                        //20210423 处理vip状态 end

                        userInfoService.modifyWxUserInfo(userInfo);

                        userGroupGzhService.updateLastActiveTimeAndPhoneModels(springProfilesActive,userInfo.getWxUnionId());
                        //嫌疑人自动拉黑 start  //getUserService()不再返回头像和昵称
//                        boolean r = wantedUsersService.checkAvatar(userId, userWxInfo.getNickname());
//                        if (r) {
//                            userInfoService.setBlockState(userId);
//                        }
                        //嫌疑人自动拉黑 end

                    } catch (Exception e) {
                        log.info("[WechatHandler]_receiveWxReq_setVipState_error:" + e.getMessage());
                    }
                    //endregion 20210126 更新用户的状态

                    //region 当用户是关注状态的时候，才进行推送前提条件设置
                    if (userSubStatus == 1) {

                        Object wxPushUser = redisCacheUtil.getCacheObject("wxPushUser" + userId);
                        log.info("[ActiveAgainUser] = " + wxPushUser);

                        //获取数据库中的记录状态
                        //int userSubStatusInDB = Optional.ofNullable(userInfoService.getUserConcernStatus(userId)).orElse(0);

                        //当用户再次点击菜单时，如果redis中相关key已经过期，则发送新的提醒
                        if (wxPushUser == null) {

                            //如果此时，数据库中也是关注状态，说明是未活跃用户重新活跃，此时发送推荐文章
                            //if (userSubStatusInDB == 1) {
                            //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userOpenId);
                            try {
                                sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userId.toString(), platformSysInfo);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            //}

                        } else {

                            WxPushUserInfo wxPushUserInfo = JSONObject.parseObject((String) wxPushUser, WxPushUserInfo.class);

                            String cacheTime = wxPushUserInfo.getCacheTime();
                            if (StringUtils.isNotBlank(cacheTime)) {
                                int hours = DateUtil.getTimeDiff(3, cacheTime);

                                //if (hours >= 45 && userSubStatusInDB == 1) {
                                if (hours >= 30) {
                                    //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userOpenId);
                                    try {
                                        sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userId.toString(), platformSysInfo);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }

                        WxPushUserInfo wxPushUserInfo = new WxPushUserInfo();
                        wxPushUserInfo.setUserId(userId);
                        wxPushUserInfo.setOpenId(userOpenId);
                        wxPushUserInfo.setCacheTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
                        redisCacheUtil.setCacheObject("wxPushUser" + userId, JSON.toJSONString(wxPushUserInfo), 172800);

                        //清除查看文章推送计数
                        redisCacheUtil.removeSingleCache(userId + "lookArticleWxPushTimes");

                    }
                    //endregion 当用户是关注状态的时候，才进行推送前提条件设置

                }
            }
            //log.error("执行receiveWxReq结束(--)："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
            if (outMessage == null) {
                return "";
            }

            out = outMessage.toXml();



        } else if ("aes".equals(encType)) {
            // aes加密的消息
            WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody,
                    weixinService.getWxMpConfigStorage(), timestamp, nonce, msgSignature);
            log.info("消息解密后内容为：{} ", inMessage.toString());

            if (inMessage != null && inMessage.getEvent() != null && inMessage.getEvent().toUpperCase().equals("TEMPLATESENDJOBFINISH")) {//如果是模板消息的回调，直接返回 success

                log.info("捕捉到TEMPLATESENDJOBFINISH");
                return "success";
            }

            //添加缓存信息
            String userOpenId = inMessage.getFromUser();
            if (StringUtils.isNotBlank(userOpenId)) {

                Integer userId = userInfoService.getUserStatusByOpenId(userOpenId);
                if (userId != null && userId.intValue() > 0) {

                    int userSubStatus = 0;

                    WxMpUser userWxInfo = new WxMpUser();
                    try {
                        userWxInfo = weixinService.getUserService().userInfo(inMessage.getFromUser(), null);
                        boolean userSubscribeStatus = userWxInfo.getSubscribe();
                        if (userSubscribeStatus) {
                            userSubStatus = 1;
                        }

                    } catch (WxErrorException e) {
                        e.printStackTrace();
                    }

                    //region 20210126 更新用户的状态
                    try {
                        UserInfo userInfo = new UserInfo();
                        userInfo.setUserId(userId);
                        userInfo.setWxUnionId(userWxInfo.getUnionId());
                        userInfo.setConcernStatus(userSubStatus);
                        userInfo.setLastActiveTime(DateUtil.getCurDate());
                        //userInfo.setUserName(userWxInfo.getNickname());//getUserService()不再返回头像和昵称


                        if (userSubStatus == 1 && userWxInfo.getSubscribeTime() != null && userWxInfo.getSubscribeTime() > 0) {  //20210126
                            userInfo.setSubscribeTime(DateUtil.timeStampToDate(userWxInfo.getSubscribeTime().toString()));
                        }

                        if (sysGzh != null && sysGzh.getOpenGroupCode() != null && sysGzh.getOpenGroupCode().trim().length() > 0) {
                            userInfo.setOpenGroupCode(sysGzh.getOpenGroupCode());//开放平台分组标识
                        }

                        //20210423 处理vip状态 start
                        UserVipValidInfo userVipValidInfoInDB = vipInfoService.getVipValidInfo(userId);
                        if (userVipValidInfoInDB != null
                                && userVipValidInfoInDB.getBeginTime()!= null
                                && userVipValidInfoInDB.getEndTime() != null
                                && userVipValidInfoInDB.getBeginTime().getTime() < DateUtil.getCurDate().getTime()
                                && DateUtil.getCurDate().getTime() < userVipValidInfoInDB.getEndTime().getTime()) {//开始时间 和 结束时间 之内
                            userInfo.setVipStatus(1);
                        } else {
                            userInfo.setVipStatus(0);//把vip关掉
                        }
                        //20210423 处理vip状态 end

                        userInfoService.modifyWxUserInfo(userInfo);

                        userGroupGzhService.updateLastActiveTimeAndPhoneModels(springProfilesActive,userInfo.getWxUnionId());

                        //嫌疑人自动拉黑 start  //getUserService()不再返回头像和昵称
//                        boolean r = wantedUsersService.checkAvatar(userId, userWxInfo.getNickname());
//                        if (r) {
//                            userInfoService.setBlockState(userId);
//                        }
                        //嫌疑人自动拉黑 end

                    } catch (Exception e) {
                        log.info("[WechatHandler]_receiveWxReq_setVipState_error:" + e.getMessage());
                    }
                    //endregion 20210126 更新用户的状态

                    //region 当用户是关注状态的时候，才进行推送前提条件设置
                    if (userSubStatus == 1) {

                        Object wxPushUser = redisCacheUtil.getCacheObject("wxPushUser" + userId);
                        log.info("[ActiveAgainUser] = " + wxPushUser);

                        //获取数据库中的记录状态
                        //int userSubStatusInDB = Optional.ofNullable(userInfoService.getUserConcernStatus(userId)).orElse(0);

                        //当用户再次点击菜单时，如果redis中相关key已经过期，则发送新的提醒
                        if (wxPushUser == null) {

                            //if (userSubStatusInDB == 1) {
                            //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userOpenId);
                            try {
                                //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userId.toString(), platformSysInfo); //20210909 屏蔽
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            //}

                        } else {

                            WxPushUserInfo wxPushUserInfo = JSONObject.parseObject((String) wxPushUser, WxPushUserInfo.class);

                            String cacheTime = wxPushUserInfo.getCacheTime();
                            if (StringUtils.isNotBlank(cacheTime)) {
                                int hours = DateUtil.getTimeDiff(3, cacheTime);

                                //if (hours >= 45 && userSubStatusInDB == 1) {
                                if (hours >= 30) {
                                    //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userOpenId);
                                    try {
                                        //sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userId.toString(), platformSysInfo);//20210909 屏蔽
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }

                        WxPushUserInfo wxPushUserInfo = new WxPushUserInfo();
                        wxPushUserInfo.setUserId(userId);
                        wxPushUserInfo.setOpenId(userOpenId);
                        wxPushUserInfo.setCacheTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
                        redisCacheUtil.setCacheObject("wxPushUser" + userId, JSON.toJSONString(wxPushUserInfo), 172800);

                        //清除查看文章推送计数
                        redisCacheUtil.removeSingleCache(userId + "lookArticleWxPushTimes");

                    }
                    //endregion 当用户是关注状态的时候，才进行推送前提条件设置

                    //region （公众号做通）20210902 添加公众号openid与userid映射
                    UserGroupGzh userGroupGzh = userGroupGzhService.getUserGroupGzh(springProfilesActive);//查看当前公众号 在不在 公众号组里
                    if (userGroupGzh != null && userGroupGzh.getGroupCode() != null ) {
                        Integer groupUserId = userGroupGzhService.getUserGroupUserId(springProfilesActive, userOpenId, sysGzh.getAppId(), userWxInfo.getUnionId(), userGroupGzh.getGroupCode());
                    }
                    //endregion

                }

                //region 20210808 hyl 复制个人信息(启客宝->开单爆文、掌柜推手)
//                log.error("执行receiveWxReq updateUserIdByUnionId 开始："+userId+"_"+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
//                try {
//                    if (springProfilesActive != null
//                            //&& (springProfilesActive.equals("back_zkt"))) {
//                        && (springProfilesActive.equals("prodkdbw") )) {
//                        //userInfoService.getUserByImg("prodqkb",userWxInfo.getNickname(),userWxInfo.getHeadImgUrl(),finalUserId);
//                        WxMpUser userWxInfo = weixinService.getUserService().userInfo(inMessage.getFromUser(), null);
//                        Integer actUserId= userInfoService.updateUserIdByUnionId(userWxInfo,userId,"prodqkb",springProfilesActive);
//                    }
//                } catch (Exception e) {
//
//                }
//                log.error("执行receiveWxReq updateUserIdByUnionId 结束："+userId+"_"+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
                //endregion
            }

            WxMpXmlOutMessage outMessage = weixinService.route(inMessage);

            //log.error("执行receiveWxReq结束(aes)："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
            if (outMessage == null) {
                return "";
            }

            out = outMessage.toEncryptedXml(weixinService.getWxMpConfigStorage());
        }



        return out;
    }

    /**
     * 微信授权
     * @param returnUrl
     * @return
     */
    @GetMapping("/authorize")
    public void authorize(@RequestParam("identifying") String springProfilesActive,@RequestParam("returnUrl") String returnUrl) {
        //log.error("执行authorize开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        //String url = wechatAccountConfig.getAuthorizeRedirectUrl();
        String url =platformSysInfoConfig.getAuthorizeRedirectUrl();

        log.info("[authorizeRedirectUrl] = " + url);
        WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(springProfilesActive);
        if(weixinService==null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            WeixinServiceMap.putWeixinService(springProfilesActive,weixinService);
        }

        String redirectURL = null;
        try {
            redirectURL = weixinService.oauth2buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_BASE, URLEncoder.encode(returnUrl, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        log.info("[WxCodeUrl] = " + redirectURL);

        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = attributes.getResponse();

        try {
            log.error("执行authorize结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate())+"_redirectURL:"+redirectURL);
            response.sendRedirect(redirectURL);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @GetMapping("/jumpToRedirectUrl")
    public void jumpToRedirectUrl(@RequestParam("code") String code, @RequestParam("state") String redirectUrl) {

        //log.error("执行jumpToRedirectUrl开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = attributes.getResponse();

        try {
            //redirectUrl = redirectUrl.replace("#/", "").trim();
//            if (redirectUrl.contains("?")) {
//                redirectUrl = redirectUrl + "&code=" + code;
//            } else {
                redirectUrl = redirectUrl + "?code=" + code;
//            }
            //log.error("执行jumpToRedirectUrl结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate())+"_redirectURL:"+redirectUrl);
            response.sendRedirect(redirectUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取微信用户access_token
     * @return
     */
//    @PostMapping(value = "/getUserAccessToken", produces="application/json;charset=UTF-8")
//    public RespData getUserAccessToken() {
//
//        String accessToken = null;
//
//        try {
//            accessToken = weixinService.getAccessToken(false);
//        } catch (WxErrorException e) {
//            e.printStackTrace();
//        }
//
//        RespData respData = new RespData();
//        respData.setCode(ReturnCode.NORMAL_SUCC);
//
//        Map<String, String> resultMap = Maps.newHashMapWithExpectedSize(2);
//        resultMap.put("accessToken", accessToken);
//
//        respData.setData(resultMap);
//        respData.setMsg("成功");
//        return respData;
//
//    }

    @GetMapping("/getMainGzhUserSession")
    public RespData getMainGzhUserSession(@RequestParam("userId") String userId) {
        log.error("getMainGzhUserSession:"+userId);
        try {

            String openId = null;
            if (userId!=null) {

                openId = userInfoService.getUserOpenId(Integer.parseInt(userId));

                RespData respData = new RespData();
                respData.setCode(ReturnCode.NORMAL_SUCC);

                Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);
                resultMap.put("userId", userId);
                resultMap.put("userSessionId", md5Encode(userId+openId));

                respData.setData(resultMap);
                respData.setMsg("成功");
                return respData;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    @PostMapping("/wxUserLogin")
    public RespData wxUserLogin(@RequestHeader("identifying") String springProfilesActive,@RequestBody WxUserLoginReqBean wxUserLoginReqBean) throws Exception {
        //log.error("执行wxUserLogin开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        if (wxUserLoginReqBean == null || StringUtils.isBlank(wxUserLoginReqBean.getCode())) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数错误");
            return respData;
        }

//        if (springProfilesActive.equals("prodqkb")) {//启客宝
//            RespData respData = new RespData();
//            respData.setCode(ReturnCode.CLIENT_ERROR);
//            respData.setMsg("参数错误");
//            return respData;
//        }

        PlatformSysInfo platformSysInfoConfig = sysGzhService.getPlatformSysInfo(springProfilesActive);
        SysGzh sysGzh = platformSysInfoConfig.getSysGzh();
        //SysGzh sysGzh = sysGzhService.selectCacheLinkByGzhCode(springProfilesActive);
        //String openGroupCode = sysGzh.getOpenGroupCode();
        WeixinServiceDL weixinService = WeixinServiceMap.getWeixinService(springProfilesActive);
        if (weixinService == null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            WeixinServiceMap.putWeixinService(springProfilesActive, weixinService);
        }

        WxMpOAuth2AccessToken wxMpOAuth2AccessToken = null;
        try {
            //log.error("执行oauth2getAccessToken开始："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate())+"__wxUserLoginReqBean.getCode():"+wxUserLoginReqBean.getCode());
            wxMpOAuth2AccessToken = weixinService.oauth2getAccessToken(wxUserLoginReqBean.getCode());
            //log.error("执行oauth2getAccessToken结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        } catch (WxErrorException e) {

            log.error("授权码已过期:"+e.getMessage());

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);

            Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(2);
            resultMap.put("code", wxUserLoginReqBean.getCode());

            respData.setData(resultMap);
            respData.setMsg("授权码已过期");
            return respData;

        }

        String openId = wxMpOAuth2AccessToken.getOpenId();

        log.info("[wxOpenId] = " + openId);

        // 获取用户微信账户信息
//        WxMpUser wxMpUser = weixinService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
//        WxMpUser wxMpUser = wxMpService.getUserService().userInfo(openId);
//        if (StringUtils.isBlank(wxMpUser.getOpenId())) {
//            log.info("[wxUserNotExist]");
//        }

        //查询用户是否已经存在
        int finalUserId = Optional.ofNullable(userInfoService.getUserStatusByOpenId(openId)).orElse(0);
        log.info("[finalUserId：]" + finalUserId);
        if (finalUserId > 0) {  //openid已存在
            //log.error("调用updateUserInfo前："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
            userAsyncTask.updateUserInfo(weixinService, wxMpOAuth2AccessToken, finalUserId, sysGzh);
            //log.error("调用updateUserInfo后："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        } else { //openid不存在
            UserInfo userInfo = new UserInfo();

            try {
//                userInfo.setWxUnionId(wxMpUser.getUnionId());
//                userInfo.setNickName(wxMpUser.getNickname());
//                userInfo.setAvatarUrl(AliyunOssClientUtil.uploadFileByFileUrl2(wxMpUser.getHeadImgUrl()));//20210508
                userInfo.setOpenId(openId);
                userInfo.setCreateTime(DateUtil.getCurDate());
                userInfo.setLastActiveTime(DateUtil.getCurDate());
                userInfo.setGzhCode(springProfilesActive);//公众号标识
                userInfo.setGzhId(sysGzh.getId());

                if (sysGzh.getOpenGroupCode() != null && sysGzh.getOpenGroupCode().trim().length() > 0) {
                    userInfo.setOpenGroupCode(sysGzh.getOpenGroupCode());//开放平台分组标识
                }

                userInfoService.addWxUserInfo(userInfo);
                finalUserId = userInfo.getUserId();

                //userGroupGzhService.updateLastActiveTimeAndPhoneModels(springProfilesActive,userInfo.getWxUnionId());

            } catch (Exception e) {
                //log.error("[WechatHandler]_wxUserLogin_setVipState_error:" + e.getMessage());
            }
            //log.error("调用createUserAttachInfo前："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
            userAsyncTask.createUserAttachInfo(weixinService, wxMpOAuth2AccessToken, finalUserId,springProfilesActive);
            //log.error("调用createUserAttachInfo后："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        }

        //region 20210808 hyl 复制个人信息(启客宝->开单爆文、掌柜推手)
//        log.error("执行updateUserIdByUnionId 开始："+finalUserId+"_"+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
//
//        try {
//            if (springProfilesActive != null
//                    //&& (springProfilesActive.equals("back_zkt"))) {
//                && (springProfilesActive.equals("prodkdbw") )) {
//                //userInfoService.getUserByImg("prodqkb",userWxInfo.getNickname(),userWxInfo.getHeadImgUrl(),finalUserId);
//                WxMpUser userWxInfo = weixinService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
//                Integer actUserId= userInfoService.updateUserIdByUnionId(userWxInfo,finalUserId,"prodqkb",springProfilesActive);
//                if(actUserId!=finalUserId) {
//                    finalUserId = actUserId;
//                }
//                log.error("___userWxInfo.getOpenId()："+userWxInfo.getOpenId()+"___actUserId："+actUserId);
//            }
//        } catch (Exception e) {
//
//        }
//        log.error("执行updateUserIdByUnionId 结束："+finalUserId+"_"+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        //endregion


        //嫌疑人自动拉黑 start
        //log.error("调用checkBlock前："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        userAsyncTask.checkBlock(weixinService, wxMpOAuth2AccessToken, finalUserId);
        //log.error("调用checkBlock后："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));
        //嫌疑人自动拉黑 end


        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(3);

        //region （公众号做通）20210902 添加公众号openid与userid映射
        UserGroupGzh userGroupGzh = userGroupGzhService.getUserGroupGzh(springProfilesActive);//查看当前公众号 在不在 公众号组里
        if (userGroupGzh != null && userGroupGzh.getGroupCode() != null ) {
            WxMpUser wxMpUser = weixinService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
            Integer groupUserId = userGroupGzhService.getUserGroupUserId(springProfilesActive, openId, sysGzh.getAppId(), wxMpUser.getUnionId(), userGroupGzh.getGroupCode());
            if (groupUserId != null) {
                finalUserId = groupUserId;
            }
        }
        //endregion

        resultMap.put("userId", String.valueOf(finalUserId));
        resultMap.put("userSessionId", md5Encode(finalUserId + openId));

        //log.error("执行wxUserLogin结束："+DateUtil.getFormatDate("yyyy-MM-dd HH:mm:ss:SSS",DateUtil.getCurDate()));

        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/purchaseVipService", produces="application/json;charset=UTF-8")
    public RespData purchaseVipService(@RequestHeader("identifying") String springProfilesActive,@RequestHeader("userId") String userId, @RequestBody PurchaseVipServiceReqBean purchaseVipServiceReqBean) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        log.info("[purchaseVipService] call **** userId:"+userId);
        //vip会员类型id
        Integer vipId = purchaseVipServiceReqBean.getVipId();

        //佣金抵扣，0 不抵扣，1 抵扣
        Integer commissionDeduction = purchaseVipServiceReqBean.getCommissionDeduction();

        if (vipId == null || commissionDeduction == null || !(commissionDeduction == 0 || commissionDeduction == 1)) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数错误");
            return respData;
        }

        //根据ID获取金币价格信息
        VipPriceInfo vipPriceInfo = vipInfoService.getVipPriceInfoByVipId(vipId);
        log.info("[vipPriceInfo] **** :"+vipPriceInfo);
        if (vipPriceInfo == null) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CONFIG_OF_VIP_PRICE_NOT_EXIST);
            respData.setMsg("所购VIP不存在，请稍后再试");
            return respData;
        }

        //处理优惠券信息(会员金额)
        double totalAmount = vipPriceInfo.getVipPrice();
        //查询佣金最大抵扣金额
        double maxCommission = vipPriceInfo.getMaxCommission();

        OrderInfo orderInfo = new OrderInfo();

        UserInfo userSubTimeRelationInfo = userInfoService.getUserSubTimeRelationInfo(Integer.parseInt(userId));
        log.info("[userSubTimeRelationInfo] **** :"+userSubTimeRelationInfo);

        //查询佣金金额
        Double accountBalanceDouble;

        accountBalanceDouble = userInfoService.getUserAccountBalance(Integer.parseInt(userId));
        double accountBalance = 0;

        if(accountBalanceDouble != null) {
            accountBalance = accountBalanceDouble.doubleValue();
        }

        //剩余佣金金额
        double accountBalanceLast = accountBalance;

        //佣金抵扣，0 不抵扣，1 抵扣
        if(userSubTimeRelationInfo != null && commissionDeduction == 1 && accountBalanceLast > 0){
//            UserInfo userInfoAccountBalance = userInfoService.getUserMainInfo(Integer.valueOf(userId));

            /**
             * A:totalAmount 会员金额
             * B:maxCommission 佣金最大抵扣金额
             * C:accountBalance 佣金金额
             *
             * 1.C（佣金金额） >= B（佣金最大抵扣金额）
             * 会员金额 A - B
             * 剩余佣金金额 C - B
             *
             * 2.C（佣金金额） < B（佣金最大抵扣金额）
             * 会员金额 A - C
             * 剩余佣金金额 0
             **/
            if (accountBalance >= maxCommission) {
                totalAmount = totalAmount - maxCommission;

                orderInfo.setDiscountStatus(1);
                orderInfo.setDiscountAmount(maxCommission);

                accountBalanceLast = accountBalance - maxCommission;

                /**
                 *使用精确小数BigDecimal
                 */
                BigDecimal bg = new BigDecimal(accountBalanceLast);
                /**
                 * 参数：
                 newScale - 要返回的 BigDecimal 值的标度。
                 roundingMode - 要应用的舍入模式。
                 返回：
                 一个 BigDecimal，其标度为指定值，其非标度值可以通过此 BigDecimal 的非标度值乘以或除以十的适当次幂来确定。
                 */
                accountBalanceLast = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

//                userInfoAccountBalance.setAccountBalance(accountBalance - maxCommission);
            }else if(accountBalance > 0){
                totalAmount = totalAmount - accountBalance;

                orderInfo.setDiscountStatus(1);
                orderInfo.setDiscountAmount(accountBalance);

                accountBalanceLast = 0;
//                userInfoAccountBalance.setAccountBalance(0.0d);
            }

            // 更新佣金金额
//            this.userInfoService.modifyUserAccountBalance(userInfoAccountBalance);
        }else if (userSubTimeRelationInfo != null && commissionDeduction == 0) {

            Date subscriberTime = userSubTimeRelationInfo.getCreateTime();

            int vipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(Integer.parseInt(userId))).orElse(0);

            //if (subscriberTime != null && vipStatus == 0) {
            if (subscriberTime != null ) { //20200901

                //优惠券剩余有效时间
                double couponRemainTime = SysConstant.COUPON_VALID_TIME - DateUtil.getTimeDiff(3, subscriberTime);
                if (couponRemainTime < 0 || couponRemainTime > 26) {
                    // 20200429 yl 获取客服手动添加的优惠卷 start
                    Object cacheObject = redisCacheUtil.getCacheObject(WechatHandler.COUPON_PRE + userId);
                    if (null != cacheObject){
                        UserInfo userInfo = JSONObject.parseObject((String) cacheObject, UserInfo.class);
                        double accuracyCouponRemainTime =  (WechatHandler.COUPON_TIMELINESS - DateUtil.getTimeDiff(2,userInfo.getCreateTime())) / 60;
                        couponRemainTime = Double.parseDouble(String.format("%.1f", accuracyCouponRemainTime)) < 0 ? 0 :Double.parseDouble(String.format("%.1f", accuracyCouponRemainTime));
                    }else {
                        couponRemainTime = 0;
                    }
                    // 20200429 yl 获取客服手动添加的优惠卷 ent
                }

                if (couponRemainTime > 0) {

                    totalAmount = totalAmount - vipPriceInfo.getCoupon();
                    if (totalAmount < 0) {
                        totalAmount = 0;
                    }

                    orderInfo.setDiscountStatus(1);
                    orderInfo.setDiscountAmount(vipPriceInfo.getCoupon().doubleValue());

                }

            }

        }

        orderInfo.setOrderId(ToolUtil.generateOrderId());
        orderInfo.setTransStatus(SysConstant.ORDER_PRE_PAY_STATUS);

        if (totalAmount < 0) {
            totalAmount = 0;
        }
        orderInfo.setTotalAmount(totalAmount);
        orderInfo.setTransType(SysConstant.ORDER_TRANS_TYPE_PURCHASE_VIP);
        orderInfo.setUserId(Integer.parseInt(userId));
        orderInfo.setItemId(vipPriceInfo.getId());
        orderInfo.setSubject("购买VIP服务");
        orderInfo.setCreateTime(DateUtil.getCurDate());

        if(purchaseVipServiceReqBean!=null && purchaseVipServiceReqBean.getMobileType()!=null){//20201215 hyl 添加用户点进来的 渠道
            orderInfo.setMobileType(purchaseVipServiceReqBean.getMobileType());
        }

        orderInfoService.doRecordOrderInfo(orderInfo);

        log.info("[orderInfo] **** :"+orderInfo.toString());

        WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
        orderRequest.setBody("购买VIP服务");
        orderRequest.setOutTradeNo(orderInfo.getOrderId());
        orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen(orderInfo.getTotalAmount().toString()));//元转成分

        //获取当前用户openId
        String openId = userInfoService.getUserOpenId(Integer.valueOf(userId));

        //region （公众号做通）20210902
        UserGroupOpenId ugoId= userGroupGzhService.getUserOpenId(springProfilesActive,Integer.valueOf(userId));
        if(ugoId!=null){
            openId=ugoId.getOpenId();
        }
        //endregion

        orderRequest.setOpenid(openId);

        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        log.info("[attributes] **** :"+attributes);
        orderRequest.setSpbillCreateIp(ToolUtil.getIpAddress(attributes.getRequest()));
        //我这里是微信公众号内打开的h5页面 type使用 JSAPI 根据业务场景变更
        orderRequest.setTradeType(WxPayConstants.TradeType.JSAPI);

        // 支付成功后跳转页面  这里需要对url进行编码
        orderRequest.setNotifyUrl(platformSysInfoConfig.getPayCallbackUrl());

        //商品ID
        orderRequest.setProductId(String.valueOf(orderInfo.getItemId()));
        log.info("[orderRequest] **** :"+orderRequest);
        // 调用sdk提供的统一下单方法 createOrder会返回重新组装后的对象 建议使用这个
        Object unOrder = null;
        try {
            WxPayService wxPayService= WechatPayDL.wxPayServiceDL(platformSysInfoConfig.getSysGzh());
            unOrder = wxPayService.createOrder(orderRequest);
            log.info("[unOrder] **** :"+unOrder);
        } catch (WxPayException e) {
            e.printStackTrace();
        }
        // 这个可能是偏向原生一点的统一下单，返回的参数有很多没用的 或者null值 建议使用 createOrder下单
        // wxService.unifiedOrder(orderRequest);

        Map<String,Object> resultMap = Maps.newLinkedHashMap();
        resultMap.put("orderId", orderInfo.getOrderId());

        /**
         *使用精确小数BigDecimal
         */
        BigDecimal bg = new BigDecimal(accountBalanceLast);
        /**
         * 参数：
         newScale - 要返回的 BigDecimal 值的标度。
         roundingMode - 要应用的舍入模式。
         返回：
         一个 BigDecimal，其标度为指定值，其非标度值可以通过此 BigDecimal 的非标度值乘以或除以十的适当次幂来确定。
         */
        double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

        resultMap.put("accountBalanceLast", f1);

        //佣金抵扣，0 不抵扣，1 抵扣
        if(commissionDeduction == 1) {
            //佣金余额缓存到redis
            redisCacheUtil.setCacheObject(WECHATPAYACCOUNTBALANCELAST + orderInfo.getOrderId() + userId, f1, 180000);
        }

        resultMap.put("payInfo", unOrder);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
    }

    @RequestMapping("/wxPayCallback/{gzhCode}")
    public String wxPayCallback(HttpServletRequest request, HttpServletResponse response,@PathVariable String gzhCode) {
        try {
            String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());

            log.info("[wxPayCallBackResult] = " + xmlResult);

            //String gzhCode=request.getParameter("gzhCode");
            PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(gzhCode);
            WxPayService  wxPayService =WechatPayDL.wxPayServiceDL(platformSysInfoConfig.getSysGzh());
            WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlResult);
            // 结果正确
            String orderNo = result.getOutTradeNo();
            String tradeNo = result.getTransactionId();
            String totalFee = BaseWxPayResult.fenToYuan(result.getTotalFee());

            log.info("[orderNo] = " + orderNo + " [tradeNo] = " + " [totalFee] = " + totalFee);

            //自己处理订单的业务逻辑，需要判断订单是否已经支付过，否则可能会重复调用
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.setOrderId(orderNo);
            orderInfo.setTradeNo(tradeNo);
            orderInfo.setTotalAmount(Double.valueOf(totalFee));
            orderInfo.setTransStatus(SysConstant.ORDER_ALREADY_PAY_STATUS);

//            WeixinServiceDL weixinService= objectFactory.getObject();
//            weixinService.reSetConfigStorage(gzhCode);
            //WxMpServiceImpl weixinService = WeixinServiceNew.getWeixinService(platformSysInfoConfig.getSysGzh());
            WeixinServiceDL weixinService= WeixinServiceMap.getWeixinService(gzhCode);
            orderInfoService.doPayCallBackProcess(orderInfo,platformSysInfoConfig,weixinService);

            return WxPayNotifyResponse.success("处理成功!");
        } catch (Exception e) {
            log.error("微信回调结果异常,异常原因{}", e.getMessage());
            e.printStackTrace();
            return WxPayNotifyResponse.fail(e.getMessage());
        }
    }


    @PostMapping(value = "/createWxMenu_prodqkb", produces="application/json;charset=UTF-8")
    public RespData createWxMenu_prodqkb(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流素材");
        wxMenuButton1.setType(WxConsts.MenuButtonType.CLICK);
        wxMenuButton1.setKey("GOTO_KHZZZS");

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("早晚安");
        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
        wxMenuButton2.setKey("GOTO_KHZZZS");

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");
        wxMenuButton3.setType(WxConsts.MenuButtonType.CLICK);
        wxMenuButton3.setKey("GOTO_KHZZZS");

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    // 人脉广场和团队 取消
    // 邀请有奖 -> 海报页
    // 客户 -> 两个选项的页面

    //region 菜单-常规
    @PostMapping(value = "/createWxMenu", produces="application/json;charset=UTF-8")
    public RespData createWxMenu(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt") || springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")

        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

//        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
//        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

//        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu1.setName("\uD83D\uDC6B团队管理");
//        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
//        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
//        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        //危险时期暂时屏蔽
        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

//        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu3.setName("我的微站");
//        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    /**
     * 教培项目生成菜单
     * @param springProfilesActive
     * @param wxNum
     * @return
     */
    @PostMapping(value = "/createWxMenuOfJP", produces="application/json;charset=UTF-8")
    public RespData createWxMenuOfJP(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        // 左边
        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("素材\uD83D\uDD25");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        subWxMenu1ButtonOfMenu1.setName("\uD83D\uDD25素材");
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("\uD83D\uDD56早晚安打卡");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("➕添加文章");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        subWxMenu4ButtonOfMenu1.setName("\uD83D\uDCE2我的广告");
        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getUserAdvertUrl());


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

        // 中间
        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("意向客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        // 右边
        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        //危险时期暂时屏蔽
        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("\uD83D\uDC8E会员权益");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("个人中心");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCCA数据中心");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu3.setUrl(platformSysInfoConfig.getDataCenterUrl());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
        subWxMenu5ButtonOfMenu3.setName("使用指南");
        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getOperatingGuide());

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    //所有机型 去掉开通会员(危险时期)
    @PostMapping(value = "/createWxMenuNoVip", produces="application/json;charset=UTF-8")
    public RespData createWxMenuNoVip(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt") || springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")

        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        subWxMenu4ButtonOfMenu1.setName("\uD83D\uDC6B团队管理");
        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

//        //危险时期暂时屏蔽
//        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
//        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

//        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu3.setName("我的微站");
//        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
//        wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    //所有机型 去掉开通会员/文章库(危险时期)
    @PostMapping(value = "/createWxMenuNoVipAndRes", produces="application/json;charset=UTF-8")
    public RespData createWxMenuNoVipAndRes(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt") || springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")

        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        subWxMenu4ButtonOfMenu1.setName("\uD83D\uDC6B团队管理");
        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        //wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

//        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
//        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

//        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu3.setName("我的微站");
//        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        //wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
        //wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    /**
     * yl 20200623
     * 创建ios个性化菜单
     * @param wxNum
     * @return
     */
    @PostMapping(value = "/createWxMenuios", produces="application/json;charset=UTF-8")
    public RespData createWxMenuIos(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt")|| springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")
        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        subWxMenu4ButtonOfMenu1.setName("\uD83D\uDC6B团队管理");
        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

//        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu3.setName("我的微站");
//        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
        //wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        // 匹配字段
        WxMenuRule wxMenuRule = new WxMenuRule();
        wxMenuRule.setClientPlatformType("1");
        wxMenu.setMatchRule(wxMenuRule);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuCreate(wxMenu);

        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }
    //endregion

    @PostMapping(value = "/createWxMenuXCX", produces="application/json;charset=UTF-8")
    public RespData createWxMenuXCX(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt") || springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")

        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        if (springProfilesActive.equalsIgnoreCase("prodhyxt") || springProfilesActive.equalsIgnoreCase("prodhysck")) {
            subWxMenu4ButtonOfMenu1.setName("\uD83D\uDD25护眼素材库");
            subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.MINIPROGRAM);
            subWxMenu4ButtonOfMenu1.setAppId("wxb0f54660c25b84ad");
            subWxMenu4ButtonOfMenu1.setPagePath("pages/home/home");
            subWxMenu4ButtonOfMenu1.setUrl("http://mp.weixin.qq.com");
        }
        if (springProfilesActive.equalsIgnoreCase("prodshjj") || springProfilesActive.equalsIgnoreCase("prodshsck")) {
            subWxMenu4ButtonOfMenu1.setName("\uD83D\uDD25私护素材库");
            subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.MINIPROGRAM);
            subWxMenu4ButtonOfMenu1.setAppId("wxdc3df6682cf2d1f0");
            subWxMenu4ButtonOfMenu1.setPagePath("pages/home/home");
            subWxMenu4ButtonOfMenu1.setUrl("http://mp.weixin.qq.com");
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);//小程序
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        //危险时期暂时屏蔽
        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("\uD83D\uDC6B团队管理");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

//        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu2ButtonOfMenu3.setName("我的微站");
//        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }

    @PostMapping(value = "/createWxMenuXCXios", produces="application/json;charset=UTF-8")
    public RespData createWxMenuXCXios(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("引流\uD83D\uDD25打卡");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        String menu1Name="\uD83D\uDD25文章/视频";
        if(springProfilesActive.equals("prodbkwz")){
            menu1Name="\uD83D\uDD25鼻康文章/视频";
            wxMenuButton1.setName("鼻康微站\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodshjj") || springProfilesActive.equals("prodshsck")) {
            menu1Name = "\uD83C\uDF39私护文章/视频";
            wxMenuButton1.setName("私护素材\uD83D\uDC9D");
        }else if(springProfilesActive.equals("prodhyxt")|| springProfilesActive.equals("prodhysck")) {
            menu1Name = "\uD83D\uDC40护眼文章/视频";
            wxMenuButton1.setName("护眼素材\uD83D\uDD25");
        }else if(springProfilesActive.equals("prodzx1")) {
            menu1Name = "\uD83D\uDC40装修文章/视频";
            wxMenuButton1.setName("装修素材\uD83D\uDD25");
        }

        subWxMenu1ButtonOfMenu1.setName(menu1Name);
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        if (springProfilesActive.equalsIgnoreCase("prodzx1") ||  //专业号
                springProfilesActive.equalsIgnoreCase("prodhyxt") ||
                springProfilesActive.equalsIgnoreCase("prodhysck") ||
                springProfilesActive.equalsIgnoreCase("prodxscja")||
                springProfilesActive.equalsIgnoreCase("prodbdxzs")||
                springProfilesActive.equalsIgnoreCase("back_zkt")||
                springProfilesActive.equalsIgnoreCase("prodshjj")||
                springProfilesActive.equalsIgnoreCase("prodshsck")||
                springProfilesActive.equalsIgnoreCase("prodbkwz")
        ){
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl().replace("list.html","listTxp.html"));
        }else {//非专业号
            subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());
        }

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        if (springProfilesActive.equalsIgnoreCase("prodhyxt") || springProfilesActive.equalsIgnoreCase("prodhysck")) {
            subWxMenu4ButtonOfMenu1.setName("\uD83D\uDD25护眼素材库");
            subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.MINIPROGRAM);
            subWxMenu4ButtonOfMenu1.setAppId("wxb0f54660c25b84ad");
            subWxMenu4ButtonOfMenu1.setPagePath("pages/home/home");
            subWxMenu4ButtonOfMenu1.setUrl("http://mp.weixin.qq.com");
        }
        if (springProfilesActive.equalsIgnoreCase("prodshjj") || springProfilesActive.equalsIgnoreCase("prodshsck")) {
            subWxMenu4ButtonOfMenu1.setName("\uD83D\uDD25私护素材库");
            subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.MINIPROGRAM);
            subWxMenu4ButtonOfMenu1.setAppId("wxdc3df6682cf2d1f0");
            subWxMenu4ButtonOfMenu1.setPagePath("pages/home/home");
            subWxMenu4ButtonOfMenu1.setUrl("http://mp.weixin.qq.com");
        }

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("\uD83D\uDD55早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83D\uDCDD添加文章/视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu5ButtonOfMenu1.setKey(SysConstant.ADD_ARTICLE_VIDEO);


        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("个人中心");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("\uD83D\uDC6B团队管理");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getArticleListMenuUrl()+"?return=2" );

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("\uD83D\uDCB0邀请有奖");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
        subWxMenu4ButtonOfMenu3.setName("联系客服");
        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu4ButtonOfMenu3.setKey(SysConstant.V1003_CLASS_KEFU2);

//        WxMenuButton subWxMenu5ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu5ButtonOfMenu3.setName("开单学院");
//        subWxMenu5ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu5ButtonOfMenu3.setUrl(platformSysInfoConfig.getFrontDomain()+"pages/commercialCollege/index.html");//自开发的商学院

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);
        //wxMenuButton3List.add(subWxMenu5ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        // 匹配字段
        WxMenuRule wxMenuRule = new WxMenuRule();
        wxMenuRule.setClientPlatformType("1");
        wxMenu.setMatchRule(wxMenuRule);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuCreate(wxMenu);

        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    //region 菜单-多锁客
    //多锁客
    @PostMapping(value = "/createWxMenuDSK", produces="application/json;charset=UTF-8")
    public RespData createWxMenuDSK(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {
        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("获客素材\uD83D\uDD25");

//        WxMenuButton subWxMenu1ButtonOfMenu0 = new WxMenuButton();
//        subWxMenu1ButtonOfMenu0.setName("一键招商\uD83D\uDCB0");
//        subWxMenu1ButtonOfMenu0.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu1ButtonOfMenu0.setUrl(platformSysInfoConfig.getFrontDomain()+"/pages/officialAccounts/haohuoneigou.html");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        subWxMenu1ButtonOfMenu1.setName("\uD83D\uDD25获客爆文");
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("⏰早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
        subWxMenu4ButtonOfMenu1.setName("使用指南");
        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getTutorialUrl());

//        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu3ButtonOfMenu1.setName("获取人脉");
//        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
//        subWxMenu3ButtonOfMenu1.setKey(platformSysInfoConfig.getGetNetworkMenuEventKey());

        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
//        wxMenuButton1List.add(subWxMenu1ButtonOfMenu0);
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("设置名片");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("我的微站");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("邀请有奖\uD83D\uDCB0");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

//        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu3.setName("合作/代理");
//        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUrl());

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    //多锁客ios
    @PostMapping(value = "/createWxMenuDSKios", produces="application/json;charset=UTF-8")
    public RespData createWxMenuDSKios(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {
        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("获客素材\uD83D\uDD25");

//        WxMenuButton subWxMenu1ButtonOfMenu0 = new WxMenuButton();
//        subWxMenu1ButtonOfMenu0.setName("一键招商\uD83D\uDCB0");
//        subWxMenu1ButtonOfMenu0.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu1ButtonOfMenu0.setUrl(platformSysInfoConfig.getFrontDomain()+"/pages/officialAccounts/haohuoneigou.html");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        subWxMenu1ButtonOfMenu1.setName("\uD83D\uDD25获客爆文");
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("⏰早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

//        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu1.setName("使用指南");
//        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getTutorialUrl());

        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
//        wxMenuButton1List.add(subWxMenu1ButtonOfMenu0);
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
//        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("设置名片");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("我的微站");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("邀请有奖\uD83D\uDCB0");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

//        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu3.setName("合作/代理");
//        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUrl());

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        //  wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        //wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        // 匹配字段
        WxMenuRule wxMenuRule = new WxMenuRule();
        wxMenuRule.setClientPlatformType("1");
        wxMenu.setMatchRule(wxMenuRule);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuCreate(wxMenu);

        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }
    //endregion

    //region 菜单-金牌社交
    @PostMapping(value = "/createWxMenuJP", produces="application/json;charset=UTF-8")
    public RespData createWxMenuJP(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {
        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("获客素材\uD83D\uDD25");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        subWxMenu1ButtonOfMenu1.setName("\uD83D\uDD25获客爆文");
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83C\uDFA5获客视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu5ButtonOfMenu1.setUrl(platformSysInfoConfig.getVideoListMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("⏰早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

//        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu1.setName("使用指南");
//        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getTutorialUrl());

//        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu3ButtonOfMenu1.setName("获取人脉");
//        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.CLICK);
//        subWxMenu3ButtonOfMenu1.setKey(platformSysInfoConfig.getGetNetworkMenuEventKey());

        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
//        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu0ButtonOfMenu3 = new WxMenuButton();
        subWxMenu0ButtonOfMenu3.setName("\uD83D\uDC51会员权益");
        subWxMenu0ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu0ButtonOfMenu3.setUrl(platformSysInfoConfig.getOpenMemberMenuUrl()+"?mt=0");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("设置名片");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("我的微站");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("邀请有奖\uD83D\uDCB0");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

//        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu3.setName("合作/代理");
//        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUrl());

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
//        wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuDelete();
            weixinService.getMenuService().menuCreate(wxMenu);
        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }


    /**
     * yl 20200623
     * 创建ios个性化菜单
     * @param wxNum
     * @return
     */
    @PostMapping(value = "/createWxMenuJPios", produces="application/json;charset=UTF-8")
    public RespData createWxMenuJPIos(@RequestHeader("identifying") String springProfilesActive,@RequestParam String wxNum) {
        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);
        WxMenu wxMenu = new WxMenu();

        WxMenuButton wxMenuButton1 = new WxMenuButton();
        wxMenuButton1.setName("获客素材\uD83D\uDD25");

        WxMenuButton subWxMenu1ButtonOfMenu1 = new WxMenuButton();
        subWxMenu1ButtonOfMenu1.setName("\uD83D\uDD25获客爆文");
        subWxMenu1ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu1.setUrl(platformSysInfoConfig.getArticleListMenuUrl());

        WxMenuButton subWxMenu5ButtonOfMenu1 = new WxMenuButton();
        subWxMenu5ButtonOfMenu1.setName("\uD83C\uDFA5获客视频");
        subWxMenu5ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu5ButtonOfMenu1.setUrl(platformSysInfoConfig.getVideoListMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu1 = new WxMenuButton();
        subWxMenu2ButtonOfMenu1.setName("⭕人脉广场");
        subWxMenu2ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu1.setUrl(platformSysInfoConfig.getConnectionPlazaUrl());

        WxMenuButton subWxMenu3ButtonOfMenu1 = new WxMenuButton();
        subWxMenu3ButtonOfMenu1.setName("⏰早晚安打卡");
        subWxMenu3ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu3ButtonOfMenu1.setUrl(platformSysInfoConfig.getClockMenuUrl());

//        WxMenuButton subWxMenu4ButtonOfMenu1 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu1.setName("使用指南");
//        subWxMenu4ButtonOfMenu1.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu1.setUrl(platformSysInfoConfig.getTutorialUrl());

        List<WxMenuButton> wxMenuButton1List = Lists.newArrayList();
        wxMenuButton1List.add(subWxMenu1ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu5ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu2ButtonOfMenu1);
        wxMenuButton1List.add(subWxMenu3ButtonOfMenu1);
//        wxMenuButton1List.add(subWxMenu4ButtonOfMenu1);

        wxMenuButton1.setSubButtons(wxMenuButton1List);

//        WxMenuButton wxMenuButton2 = new WxMenuButton();
//        wxMenuButton2.setName("⏰早晚安");
//        wxMenuButton2.setType(WxConsts.MenuButtonType.CLICK);
//        wxMenuButton2.setKey(SysConstant.V1004_CLASS_PUNCH_CLOCK);

        WxMenuButton wxMenuButton2 = new WxMenuButton();
        wxMenuButton2.setName("客户");
        wxMenuButton2.setType(WxConsts.MenuButtonType.VIEW);
        wxMenuButton2.setUrl(platformSysInfoConfig.getCustomerMenuUrl());

        WxMenuButton wxMenuButton3 = new WxMenuButton();
        wxMenuButton3.setName("个人中心");

        WxMenuButton subWxMenu1ButtonOfMenu3 = new WxMenuButton();
        subWxMenu1ButtonOfMenu3.setName("设置名片");
        subWxMenu1ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu1ButtonOfMenu3.setUrl(platformSysInfoConfig.getSetUpMenuUrl());

        WxMenuButton subWxMenu2ButtonOfMenu3 = new WxMenuButton();
        subWxMenu2ButtonOfMenu3.setName("我的微站");
        subWxMenu2ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
        subWxMenu2ButtonOfMenu3.setUrl(platformSysInfoConfig.getMicroStationMenuUrl());

        WxMenuButton subWxMenu3ButtonOfMenu3 = new WxMenuButton();
        subWxMenu3ButtonOfMenu3.setName("邀请有奖\uD83D\uDCB0");
        subWxMenu3ButtonOfMenu3.setType(WxConsts.MenuButtonType.CLICK);
        subWxMenu3ButtonOfMenu3.setKey(platformSysInfoConfig.getCooperationUseMenuEventKey());

//        WxMenuButton subWxMenu4ButtonOfMenu3 = new WxMenuButton();
//        subWxMenu4ButtonOfMenu3.setName("合作/代理");
//        subWxMenu4ButtonOfMenu3.setType(WxConsts.MenuButtonType.VIEW);
//        subWxMenu4ButtonOfMenu3.setUrl(platformSysInfoConfig.getCooperationUrl());

        List<WxMenuButton> wxMenuButton3List = Lists.newArrayList();
        //  wxMenuButton3List.add(subWxMenu0ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu1ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu2ButtonOfMenu3);
        wxMenuButton3List.add(subWxMenu3ButtonOfMenu3);
        //wxMenuButton3List.add(subWxMenu4ButtonOfMenu3);

        wxMenuButton3.setSubButtons(wxMenuButton3List);

        List<WxMenuButton> wxMenuButtons = Lists.newArrayList();
        wxMenuButtons.add(wxMenuButton1);
        wxMenuButtons.add(wxMenuButton2);
        wxMenuButtons.add(wxMenuButton3);
        wxMenu.setButtons(wxMenuButtons);

        // 匹配字段
        WxMenuRule wxMenuRule = new WxMenuRule();
        wxMenuRule.setClientPlatformType("1");
        wxMenu.setMatchRule(wxMenuRule);

        try {
            WeixinServiceDL weixinService= objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            weixinService.getMenuService().menuCreate(wxMenu);

        } catch (WxErrorException e) {
            e.printStackTrace();

            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg("失败");
            return respData;
        }

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        return respData;

    }
    //endregion

    /**
     * 商学院购买课程支付
     *
     * @param bBusinessInfo 实例对象
     * @return 实例对象
     */
    @PostMapping(value = "/buyOrderCourseService", produces = "application/json;charset=UTF-8")
    public RespData buyOrderCourseService(@RequestHeader("identifying") String springProfilesActive,@RequestHeader("userId") String userId, @RequestBody BBusinessInfo bBusinessInfo) {
        log.info("[buyOrderCourseService] call **** userId:" + userId);

        PlatformSysInfo platformSysInfoConfig= sysGzhService.getPlatformSysInfo(springProfilesActive);

        RespData respData = new RespData();

        // 购买商学院课程id
        Integer courseId = bBusinessInfo.getId();

        // 购买人的userId
        Integer userIdInt = Integer.parseInt(userId);

        // 参数判空
        if (io.micrometer.core.instrument.util.StringUtils.isBlank(userId) || bBusinessInfo == null || courseId == null) {
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        // 查询自己基础信息
        UserInfo userInfoSelf = this.userInfoService.getUserMainInfo(userIdInt);

        // 查询商学院课程是否存在
        BBusinessInfo bBusinessInfoService = this.bBusinessInfoService.queryById(courseId);
        if (bBusinessInfoService == null || bBusinessInfoService.getDeleteState() != 1) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("课程不存在！");
            return respData;
        }

        /**
         *  1-全员免费 2-会员免费/非会员付费 3-全员付费/会员和非会员价格不同
         */
        Integer rangePrice = bBusinessInfoService.getRangePrice();

        /**
         *  0-非全员 1-会员
         */
        Integer vipStatus = userInfoSelf.getVipStatus();

        // 判断商学院课程是否为付费课程 ==== 全员免费
        if (rangePrice == 1) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("课程无需购买！");
            return respData;
        }

        // 判断商学院课程是否为付费课程 ==== 会员免费/非会员付费
        if (rangePrice == 2 && vipStatus == 1) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("课程会员无需购买！");
            return respData;
        }

        // 查询是否购买过此课程 ==== 1-购买过
        Integer checkCourseStatus = orderInfoService.checkCourse(userIdInt, courseId);

        if (checkCourseStatus == 1) {
            respData.setCode(ReturnCode.NORMAL_SUCC);
            respData.setMsg("课程已购买！");
            return respData;
        }

        // 购买课程金额，默认原价
        double monetary = bBusinessInfoService.getNonMembersPrice();

        // 判断商学院课程是否为付费课程 ==== 全员付费/会员和非会员价格不同
        if (rangePrice == 3 && vipStatus == 1) {
            // 此时为会员价
            monetary = bBusinessInfoService.getMembersPrice();
        }
        if (monetary < 0) {
            monetary = 0;
        }

        /**
         *  1-全员免费 2-会员免费/非会员付费 3-全员付费/会员和非会员价格不同
         */
        // 订单表
        OrderInfo orderInfo = new OrderInfo();

        orderInfo.setOrderId(ToolUtil.generateOrderId());//交易流水号
        orderInfo.setUserId(Integer.parseInt(userId));//买家用户USERID
        orderInfo.setTotalAmount(monetary);//交易总计金额
        orderInfo.setSubject("购买商学院课程服务");//交易说明
        orderInfo.setTransStatus(SysConstant.ORDER_PRE_PAY_STATUS);//交易状态 0-等待支付 1-已支付 2-已退款
        orderInfo.setTransType(SysConstant.ORDER_TRANS_TYPE_PURCHASE_BUSINESS);//订单交易类型 2-商学院课程订单
        orderInfo.setItemId(courseId);//购买商品id,课程ID
        orderInfo.setCreateTime(DateUtil.getCurDate()); //交易发生时间

//分割线==============================================================================================
        // 记录订单信息
        orderInfoService.doRecordOrderInfo(orderInfo);

        log.info("[orderInfo] **** :"+orderInfo.toString());

        WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();

        orderRequest.setBody("购买商学院课程服务");
        orderRequest.setOutTradeNo(orderInfo.getOrderId());
        orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen(orderInfo.getTotalAmount().toString()));//元转成分

        //获取当前用户openId
        String openId = userInfoService.getUserOpenId(Integer.valueOf(userId));

        //region （公众号做通）20210902
        UserGroupOpenId ugoId= userGroupGzhService.getUserOpenId(springProfilesActive,Integer.valueOf(userId));
        if(ugoId!=null){
            openId=ugoId.getOpenId();
        }
        //endregion

        orderRequest.setOpenid(openId);

        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        log.info("[attributes] **** :"+attributes);
        orderRequest.setSpbillCreateIp(ToolUtil.getIpAddress(attributes.getRequest()));
        //我这里是微信公众号内打开的h5页面 type使用 JSAPI 根据业务场景变更
        orderRequest.setTradeType(WxPayConstants.TradeType.JSAPI);

        // 支付成功后跳转页面  这里需要对url进行编码
//        orderRequest.setNotifyUrl(wechatAccountConfig.getPayCallbackUrl());
        orderRequest.setNotifyUrl(platformSysInfoConfig.getPayCallbackUrlByBusiness());

        //商品ID
        orderRequest.setProductId(String.valueOf(orderInfo.getItemId()));
        log.info("[orderRequest] **** :"+orderRequest);
        // 调用sdk提供的统一下单方法 createOrder会返回重新组装后的对象 建议使用这个
        Object unOrder = null;
        try {
            WxPayService wxPayService= WechatPayDL.wxPayServiceDL(platformSysInfoConfig.getSysGzh());
            unOrder = wxPayService.createOrder(orderRequest);
            log.info("[unOrder] **** :"+unOrder);
        } catch (WxPayException e) {
            e.printStackTrace();
        }
        // 这个可能是偏向原生一点的统一下单，返回的参数有很多没用的 或者null值 建议使用 createOrder下单
        // wxService.unifiedOrder(orderRequest);

        Map<String,Object> resultMap = Maps.newLinkedHashMap();
        resultMap.put("orderId", orderInfo.getOrderId());

        resultMap.put("payInfo", unOrder);

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setData(resultMap);
        respData.setMsg("成功");
        return respData;
//分割线==============================================================================================
    }

    /**
     * 商学院购买课程支付回调
     *
     */
    @RequestMapping("/wxPayCallbackByBusiness/{gzhCode}")
    public String wxPayCallbackByBusiness(HttpServletRequest request, HttpServletResponse response,@PathVariable String gzhCode) {
        try {
            String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());

            log.info("[wxPayCallBackResult] = " + xmlResult);
            //String gzhCode=request.getParameter("gzhCode");
            SysGzh sysGzh= sysGzhService.selectCacheLinkByGzhCode(gzhCode);
            WxPayService  wxPayService =WechatPayDL.wxPayServiceDL(sysGzh);
            WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlResult);
            // 结果正确
            String orderNo = result.getOutTradeNo();
            String tradeNo = result.getTransactionId();
            String totalFee = BaseWxPayResult.fenToYuan(result.getTotalFee());

            log.info("[orderNo] = " + orderNo + " [tradeNo] = " + " [totalFee] = " + totalFee);

            // 自己处理订单的业务逻辑，需要判断订单是否已经支付过，否则可能会重复调用
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.setOrderId(orderNo);
            orderInfo.setTradeNo(tradeNo);
            orderInfo.setTotalAmount(Double.valueOf(totalFee));

            // 根据回调处理订单信息
            orderInfoService.doPayCallBackProcessForBusiness(orderInfo);

            return WxPayNotifyResponse.success("处理成功!");
        } catch (Exception e) {
            log.error("微信回调结果异常,异常原因{}", e.getMessage());
            e.printStackTrace();
            return WxPayNotifyResponse.fail(e.getMessage());
        }
    }
    //endregion


    @PostMapping(value = "/test", produces="application/json;charset=UTF-8")
    public RespData test(@RequestParam("nickName") String nickName) throws Exception {

        List<UserInfo> wantedUser= userInfoService.queryWantedByNickName(nickName);
        String msg="";
        String msg2="";

        for(UserInfo u:wantedUser) {
            boolean r = wantedUsersService.checkAvatar(u.getUserId(), nickName);
            if (r) {
                userInfoService.setBlockState(u.getUserId());
                msg = msg+","+u.getUserId();
            }else{
                msg2= msg2+","+u.getUserId();
            }
        }

        log.error("msg:"+msg);
        log.error("\n\nmsg2:"+msg2);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg(msg);
        return respData;
    }

    @PostMapping(value = "/changeOpenid", produces = "application/json;charset=UTF-8")
    public RespData changeOpenid(@RequestHeader("identifying") String springProfilesActive,
                                 @RequestHeader("appId") String appId,
                                 @RequestHeader("accessToken") String accessToken) {
        log.info("[accessToken] = {}", accessToken);

        /*int pageNumber = 1;// 当前页数
        int pageSize = 100;// 每页大小
        int offset = (pageNumber - 1) * pageSize;
        // 获取该公众号所有用户数量
        int records = userInfoService.getUserCountByGzhCode(springProfilesActive);
        int totalPage = records % pageSize == 0 ? records / pageSize : (records / pageSize) + 1;// 总页数*/

        //for (int i = 0; i < totalPage; i++) {
            // List<UserInfo> userInfoList = userInfoService.getUserInfoByGzhCode(springProfilesActive, offset, pageSize);// 100条
            List<UserInfo> userInfoList = userInfoService.getUserInfoByGzhCode2(springProfilesActive);// 全部用户
            if (CollectionUtils.isNotEmpty(userInfoList)) {
                for (UserInfo u : userInfoList) {
                    Integer userId = u.getUserId();// 用户 user_id
                    String openId = u.getOpenId();// 用户 open_id

                    log.info("当前用户信息：[userId] = " + userId + ", [openId] = " + openId);

                    List<String> openidList = new ArrayList<>();// 构造集合
                    openidList.add(openId);

                    String url = String.format(USER_CHANGE_OPENID_URL, accessToken);
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("from_appid", appId);
                    jsonObject.put("openid_list", openidList);
                    String responseContent = HttpClientUtils.sendPost(url, jsonObject);

                    // 获取结果集
                    JSONObject jsonObject1 = JSON.parseObject(responseContent);
                    String errcode = jsonObject1.getString("errcode");
                    //String errmsg = jsonObject1.getString("errmsg");
                    if (errcode.equals("0")) {
                        JSONArray jsonArray = jsonObject1.getJSONArray("result_list");

                        String errMsg = jsonArray.getJSONObject(0).get("err_msg").toString();
                        if (errMsg != null && errMsg.equals("ok")) {
                            String newOpenId = jsonArray.getJSONObject(0).get("new_openid").toString();// 新OpenId
                            userInfoService.updateOpenidByUserId(userId, newOpenId);// 更新用户OpenId
                            userInfoService.updateUserGroupOpenId(springProfilesActive, openId, newOpenId);// 更新用户组Openid
                        }
                    }
                }
            }
//            pageNumber++;// 下一页
//            offset = (pageNumber - 1) * pageSize;// 偏移量
        //}

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        //respData.setData(resultMap);
        return respData;
    }

    /**
     * 获取公众号的 access_token
     * @param springProfilesActive
     * @return
     */
    @PostMapping(value = "/getAccessToken", produces = "application/json;charset=UTF-8")
    public RespData getAccessToken(@RequestHeader("identifying") String springProfilesActive) {
        log.info("[springProfilesActive] = {}", springProfilesActive);

        WeixinServiceDL weixinService = WeixinServiceMap.getWeixinService(springProfilesActive);
        if (weixinService == null) {
            weixinService = objectFactory.getObject();
            weixinService.reSetConfigStorage(springProfilesActive);
            WeixinServiceMap.putWeixinService(springProfilesActive, weixinService);
        }

        String accessToken = "";

        try {
            accessToken = weixinService.getAccessToken();
        } catch (WxErrorException e) {
            e.printStackTrace();
            log.error("微信回调结果异常,异常原因{}", e.getMessage());
            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg(e.getMessage());
            return respData;
        }

        HashMap<Object, Object> resultMap = Maps.newHashMapWithExpectedSize(10);
        resultMap.put("accessToken", accessToken);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }

    /**
     * 获取公众号 AccessToken
     * @param springProfilesActive 公众号标识
     * @return
     */
    @PostMapping(value = "/accessToken", produces = "application/json;charset=UTF-8")
    public RespData accessToken(@RequestHeader("identifying") String springProfilesActive) {

        // 获取公众号信息
        SysGzh sysGzh = sysGzhService.getPlatformSysInfo(springProfilesActive).getSysGzh();
        String appId = sysGzh.getAppId();// appid
        String secret = sysGzh.getSecret();// secret

        // AccessToken 中控服务器获取 AccessToken
        String accessToken = "";
        try {
            accessToken = AccessTokenMemServer.getAccessToken(springProfilesActive, appId, secret);
        } catch (Exception e) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.SERVER_ERROR);
            respData.setMsg(e.getMessage());
            return respData;
        }

        HashMap<Object, Object> resultMap = Maps.newHashMapWithExpectedSize(10);
        resultMap.put("accessToken", accessToken);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }
}
